home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / iw / xconfig.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  14.7 KB  |  447 lines

  1. from gtk import *
  2. from iw import *
  3. from translate import _
  4.  
  5. import string
  6. import sys
  7. import iutil
  8.  
  9. """
  10. _("Video Card")
  11. _("Monitor")
  12. _("Video Ram")
  13. _("Horizontal Frequency Range")
  14. _("Vertical Frequency Range")
  15. _("Test failed")
  16. """
  17.  
  18. class XCustomWindow (InstallWindow):
  19.     def __init__ (self, ics):
  20.     InstallWindow.__init__ (self, ics)
  21.  
  22.         self.todo = ics.getToDo ()
  23.         ics.setTitle (_("Customize X Configuration"))
  24.         ics.readHTML ("xcustom")
  25.         self.ics.setNextEnabled (TRUE)
  26.         
  27.         self.didTest = 0
  28.  
  29.     def getNext (self):
  30.         newmodes = {}
  31.  
  32.         for depth in self.toggles.keys ():
  33.             newmodes[depth] = []
  34.             for (res, button) in self.toggles[depth]:
  35.                 if button.get_active ():
  36.                     newmodes[depth].append (res)
  37.  
  38.         self.todo.x.modes = newmodes
  39.         
  40.     def testPressed (self, widget, *args):
  41.         newmodes = {}
  42.  
  43.         for depth in self.toggles.keys ():
  44.             newmodes[depth] = []
  45.             for (res, button) in self.toggles[depth]:
  46.                 if button.get_active ():
  47.                     newmodes[depth].append (res)
  48.  
  49.         self.todo.x.modes = newmodes
  50.         try:
  51.             self.todo.x.test ()
  52.         except RuntimeError:
  53.             ### test failed window
  54.             pass
  55.         else:
  56.             self.didTest = 1
  57.  
  58.     def numCompare (self, first, second):
  59.         first = string.atoi (first)
  60.         second = string.atoi (second)
  61.         if first > second:
  62.             return 1
  63.         elif first < second:
  64.             return -1
  65.         return 0
  66.     
  67.     def getScreen (self):
  68.         box = GtkVBox (FALSE, 5)
  69.         box.set_border_width (5)
  70.  
  71.         hbox = GtkHBox (FALSE, 5)
  72.  
  73.     # I'm not sure what monitors handle this wide aspect resolution, so better play safe
  74.         monName = self.todo.x.monName
  75.     if (self.todo.x.vidRam and self.todo.x.vidRam >= 4096 and
  76.             ((monName and len (monName) >= 11 and monName[:11] == 'Sun 24-inch') or
  77.              self.todo.x.monName == 'Sony GDM-W900')):
  78.         self.todo.x.modes["8"].append("1920x1200")
  79.  
  80.         depths = self.todo.x.modes.keys ()
  81.         depths.sort (self.numCompare)
  82.  
  83.         self.toggles = {}
  84.         for depth in depths:
  85.             self.toggles[depth] = []
  86.             vbox = GtkVBox (FALSE, 5)
  87.             vbox.pack_start (GtkLabel (depth + _("Bits per Pixel")), FALSE)
  88.             for res in self.todo.x.modes[depth]:
  89.                 button = GtkCheckButton (res)
  90.                 self.toggles[depth].append (res, button)
  91.                 vbox.pack_start (button, FALSE)
  92.                 
  93.             hbox.pack_start (vbox)
  94.  
  95.         
  96.         test = GtkAlignment ()
  97.         button = GtkButton (_("Test this configuration"))
  98.         button.connect ("clicked", self.testPressed)
  99.         test.add (button)
  100.         
  101.         box.pack_start (hbox, FALSE)
  102.         box.pack_start (test, FALSE)
  103.         return box
  104.  
  105.     def getPrev (self):
  106.         return XConfigWindow
  107.  
  108. class MonitorWindow (InstallWindow):
  109.     def __init__ (self, ics):
  110.     InstallWindow.__init__ (self, ics)
  111.         self.ics.setNextEnabled (FALSE)
  112.         ics.setTitle (_("Monitor Configuration"))
  113.         ics.readHTML ("monitor")
  114.         self.monitor = None
  115.  
  116.     def selectCb (self, tree, node, column):
  117.         monitor = tree.node_get_row_data (node)
  118.         if not monitor:
  119.             self.ics.setNextEnabled (FALSE)
  120.             if self.hEntry and self.vEntry:
  121.                 self.hEntry.set_text ("")
  122.                 self.vEntry.set_text ("")
  123.                 self.hEntry.set_editable (FALSE)
  124.                 self.vEntry.set_editable (FALSE)
  125.         else:
  126.             self.ics.setNextEnabled (TRUE)
  127.             self.hEntry.set_text (monitor[3])
  128.             self.vEntry.set_text (monitor[2])
  129.             self.hEntry.set_editable (TRUE)
  130.             self.vEntry.set_editable (TRUE)
  131.             self.monitor = monitor
  132.  
  133.     def getNext (self):
  134.         if self.skipme:
  135.             return None
  136.         
  137.         if self.monitor:
  138.             self.todo.x.setMonitor ((self.monitor[0],
  139.                                     (self.hEntry.get_text (),
  140.                                      self.vEntry.get_text ())))
  141.         return None
  142.  
  143.     def moveto (self, ctree, area, node):
  144.         ctree.node_moveto (node, 0, 0.5, 0.0)
  145.         self.selectCb (ctree, node, -1)
  146.  
  147.     def getScreen (self):
  148.         # Don't configure X in reconfig mode.
  149.         # in regular install, check to see if the XFree86 package is
  150.         # installed.  If it isn't return None.
  151.         if (self.todo.reconfigOnly
  152.             or (not self.todo.hdList.packages.has_key('XFree86')
  153.                 or not self.todo.hdList.packages['XFree86'].selected
  154.                 or self.todo.serial)):
  155.             self.skipme = TRUE
  156.             return None
  157.         else:
  158.             self.skipme = FALSE
  159.         
  160.         
  161.         self.todo.x.probe ()
  162.         box = GtkVBox (FALSE, 5)
  163.  
  164.         monitors = self.todo.x.monitors ()
  165.         keys = monitors.keys ()
  166.         keys.sort ()
  167.         
  168.         # Monitor selection tree
  169.         ctree = GtkCTree ()
  170.         ctree.set_selection_mode (SELECTION_BROWSE)
  171.         ctree.connect ("tree_select_row", self.selectCb)
  172.  
  173.         arch = iutil.getArch()
  174.  
  175.         self.hEntry = GtkEntry ()
  176.         self.vEntry = GtkEntry () 
  177.  
  178.         select = None
  179.         for man in keys:
  180.             parent = ctree.insert_node (None, None, (man,), 2, is_leaf = FALSE)
  181.             for monitor in monitors[man]:
  182.                 node = ctree.insert_node (parent, None, (monitor[0],), 2)
  183.                 ctree.node_set_row_data (node, monitor)
  184.                 if monitor[0] == self.todo.x.monID:
  185.                     select = node
  186.                     selParent = parent
  187.  
  188.         # Add a category for a DDC probed monitor that isn't in MonitorDB
  189.         if not select and self.todo.x.monID != "Generic Monitor":
  190.             parent = ctree.insert_node (None, None, ("DDC Probed Monitor",),
  191.                                         2, is_leaf = FALSE)
  192.             node = ctree.insert_node (parent, None, (self.todo.x.monID,), 2)
  193.             monitor = (self.todo.x.monID, self.todo.x.monID, self.todo.x.monHoriz,
  194.                        self.todo.x.monVert)
  195.             ctree.node_set_row_data (node, monitor)
  196.             select = node
  197.             selParent = parent
  198.  
  199.         if select:
  200.             ctree.select (select)
  201.             ctree.expand (selParent)
  202.             ctree.connect ("draw", self.moveto, select)
  203.  
  204.         self.hEntry.set_text (self.todo.x.monHoriz)
  205.         self.vEntry.set_text (self.todo.x.monVert)        
  206.  
  207.         sw = GtkScrolledWindow ()
  208.         sw.add (ctree)
  209.         sw.set_policy (POLICY_NEVER, POLICY_AUTOMATIC)
  210.         box.pack_start (sw, TRUE, TRUE)
  211.  
  212.         # Sync adjustments
  213.         syncbox = GtkHBox (FALSE, 5)
  214.         syncbox.set_border_width (2)
  215.  
  216.         frame = GtkFrame (_("Horizontal Sync"))
  217.         hbox = GtkHBox (FALSE, 5)
  218.         hbox.set_border_width (2)
  219.         self.hEntry.set_usize (20, -1)
  220.         hbox.pack_start (self.hEntry)
  221.         hbox.pack_start (GtkLabel ("kHz"), FALSE, FALSE)
  222.         frame.add (hbox)
  223.         syncbox.pack_start (frame)
  224.  
  225.         frame = GtkFrame (_("Vertical Sync"))
  226.         hbox = GtkHBox (FALSE, 5)
  227.         hbox.set_border_width (2)
  228.         self.vEntry.set_usize (20, -1)
  229.         hbox.pack_start (self.vEntry)
  230.         hbox.pack_start (GtkLabel ("Hz"), FALSE, FALSE)
  231.         frame.add (hbox)
  232.         syncbox.pack_start (frame)
  233.  
  234.         box.pack_start (syncbox, FALSE, FALSE)
  235.         
  236.         return box
  237.  
  238. class XConfigWindow (InstallWindow):
  239.     def __init__ (self, ics):
  240.     InstallWindow.__init__ (self, ics)
  241.  
  242.         self.ics.setNextEnabled (TRUE)
  243.  
  244.         self.todo = ics.getToDo ()
  245.     self.sunServer = 0
  246.     if self.todo.x.server and len (self.todo.x.server) >= 3 and self.todo.x.server[0:3] == 'Sun':
  247.         self.sunServer = 1
  248.         else:
  249.         self.sunServer = 0            
  250.         ics.setTitle (_("X Configuration"))
  251.         ics.readHTML ("xconf")
  252.         
  253.         self.didTest = 0
  254.  
  255.     def getNext (self):
  256.         if self.skipme:
  257.             return None
  258.  
  259.         if not self.skip.get_active ():
  260.             if self.xdm.get_active ():
  261.                 self.todo.initlevel = 5
  262.             else:
  263.                 self.todo.initlevel = 3
  264.         else:
  265.             self.todo.initlevel = 3
  266.  
  267.     if not self.sunServer:
  268.         if self.custom.get_active () and not self.skip.get_active ():
  269.         return XCustomWindow
  270.  
  271.         return None
  272.  
  273.     def customToggled (self, widget, *args):
  274.         pass
  275.     
  276.     def skipToggled (self, widget, *args):
  277.         self.configbox.set_sensitive (not widget.get_active ())
  278.         self.todo.x.skip = widget.get_active ()
  279.  
  280.     def testPressed (self, widget, *args):
  281.         try:
  282.             self.todo.x.test ()
  283.         except RuntimeError:
  284.             ### test failed window
  285.             pass
  286.         else:
  287.             self.didTest = 1
  288.  
  289.     def memory_cb (self, widget, size):
  290.         self.todo.x.vidRam = size[:-1]
  291.         self.todo.x.filterModesByMemory ()
  292.  
  293.     def moveto (self, clist, area, row):
  294.         clist.select_row (row, 0)
  295.         clist.moveto (row, 0, 0.5, 0.0)
  296.  
  297.  
  298.     def selectCb (self, list, row, col, event):
  299.         cardname = list.get_row_data (row)
  300.         if cardname:
  301.             card = self.cards[cardname]
  302.             depth = 0
  303.             while depth < 16 and card.has_key ("SEE"):
  304.                 card = self.cards[card["SEE"]]
  305.                 depth = depth + 1
  306.             self.todo.x.setVidcard (card)
  307.         
  308.     def getScreen (self):
  309.         # Don't configure X in reconfig mode.
  310.         # in regular install, check to see if the XFree86 package is
  311.         # installed.  If it isn't return None.
  312.         if (self.todo.reconfigOnly
  313.             or (not self.todo.hdList.packages.has_key('XFree86')
  314.                 or not self.todo.hdList.packages['XFree86'].selected
  315.                 or self.todo.serial)):
  316.             self.skipme = TRUE
  317.             return None
  318.         else:
  319.             self.skipme = FALSE
  320.  
  321.         self.todo.x.probe ()
  322.         self.todo.x.filterModesByMemory ()
  323.  
  324.         box = GtkVBox (FALSE, 5)
  325.         box.set_border_width (5)
  326.  
  327.         self.autoBox = GtkVBox (FALSE, 5)
  328.  
  329.         arch = iutil.getArch()
  330.         if arch == "alpha":
  331.             label = GtkLabel (_("Your video ram size can not be autodetected.  "
  332.                                 "Choose your video ram size from the choices below:"))
  333.             label.set_justify (JUSTIFY_LEFT)
  334.             label.set_line_wrap (TRUE)        
  335.             label.set_alignment (0.0, 0.5)
  336.             label.set_usize (400, -1)
  337.             box.pack_start (label, FALSE)
  338.         elif arch == "i386":
  339.             # but we can on everything else
  340.             self.autoBox = GtkVBox (FALSE, 5)
  341.  
  342.             label = GtkLabel (_("In most cases your video hardware can "
  343.                                 "be probed to automatically determine the "
  344.                                 "best settings for your display."))
  345.             label.set_justify (JUSTIFY_LEFT)
  346.             label.set_line_wrap (TRUE)        
  347.             label.set_alignment (0.0, 0.5)
  348.             label.set_usize (400, -1)
  349.             self.autoBox.pack_start (label, FALSE)
  350.  
  351.             label = GtkLabel (_("If the probed settings do not match your hardware "
  352.                                 "select the correct setting below:"))
  353.             label.set_justify (JUSTIFY_LEFT)
  354.             label.set_line_wrap (TRUE)        
  355.             label.set_alignment (0.0, 0.5)
  356.             label.set_usize (400, -1)
  357.             self.autoBox.pack_start (label, FALSE)
  358.  
  359.             box.pack_start (self.autoBox, FALSE)
  360.         else:
  361.             # sparc
  362.             self.autoBox = GtkVBox (FALSE, 5)
  363.             label = GtkLabel (_("In most cases your video hardware can "
  364.                                 "be probed to automatically determine the "
  365.                                 "best settings for your display."))
  366.             label.set_justify (JUSTIFY_LEFT)
  367.             label.set_line_wrap (TRUE)        
  368.             label.set_alignment (0.0, 0.5)
  369.             label.set_usize (400, -1)
  370.             self.autoBox.pack_start (label, FALSE)
  371.  
  372.             label = GtkLabel (_("Autoprobe results:"))
  373.             label.set_alignment (0.0, 0.5)
  374.             self.autoBox.pack_start (label, FALSE)
  375.             report = self.todo.x.probeReport ()
  376.             report = string.replace (report, '\t', '       ')
  377.             result = GtkLabel (report)
  378.             result.set_alignment (0.2, 0.5)
  379.             result.set_justify (JUSTIFY_LEFT)
  380.             self.autoBox.pack_start (result, FALSE)
  381.             box.pack_start (self.autoBox, FALSE)
  382.             
  383.         # card configuration
  384.         if arch == "i386" or arch == "alpha":
  385.             self.cardList = GtkCList ()
  386.             self.cardList.set_selection_mode (SELECTION_BROWSE)
  387.             self.cardList.connect ("select_row", self.selectCb)
  388.  
  389.             self.cards = self.todo.x.cards ()
  390.             cards = self.cards.keys ()
  391.             cards.sort ()
  392.             select = 0
  393.             for card in cards:
  394.                 row = self.cardList.append ((card,))
  395.                 self.cardList.set_row_data (row, card)
  396.                 if (self.todo.x.vidCards
  397.                     and card == self.todo.x.vidCards[self.todo.x.primary]["NAME"]):
  398.                     select = row
  399.             self.cardList.connect ("draw", self.moveto, select)
  400.             sw = GtkScrolledWindow ()
  401.             sw.add (self.cardList)
  402.             box.pack_start (sw, TRUE)
  403.  
  404.             # Memory configuration table
  405.             table = GtkTable()
  406.             group = None
  407.             count = 0
  408.             for size in ("256k", "512k", "1024k", "2048k", "4096k",
  409.                          "8192k", "16384k"):
  410.                 button = GtkRadioButton (group, size)
  411.                 button.connect ('clicked', self.memory_cb, size)
  412.                 if size[:-1] == self.todo.x.vidRam:
  413.                     button.set_active (1)
  414.                 if not group:
  415.                     group = button
  416.                 table.attach (button, count % 4, (count % 4) + 1,
  417.                               count / 4, (count / 4) + 1)
  418.                 count = count + 1
  419.             box.pack_start (table, FALSE)
  420.  
  421.         if not self.sunServer:
  422.             test = GtkAlignment ()
  423.             button = GtkButton (_("Test this configuration"))
  424.             button.connect ("clicked", self.testPressed)
  425.             test.add (button)
  426.  
  427.             self.custom = GtkCheckButton (_("Customize X Configuration"))
  428.             self.custom.connect ("toggled", self.customToggled)
  429.             box.pack_start (test, FALSE)
  430.             box.pack_start (self.custom, FALSE)
  431.  
  432.         self.xdm = GtkCheckButton (_("Use Graphical Login"))
  433.         self.skip = GtkCheckButton (_("Skip X Configuration"))
  434.         self.skip.connect ("toggled", self.skipToggled) 
  435.  
  436.         box.pack_start (self.xdm, FALSE)
  437.  
  438.         self.topbox = GtkVBox (FALSE, 5)
  439.         self.topbox.pack_start (box, TRUE, TRUE)
  440.         self.topbox.pack_start (self.skip, FALSE)
  441.  
  442.         self.configbox = box
  443.  
  444.         self.skip.set_active (self.todo.x.skip)
  445.  
  446.         return self.topbox
  447.